package com.jingtai.shop.service.user.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jingtai.common.enums.DeleteFlagEnum;
import com.jingtai.core.entity.shop.Evaluation;
import com.jingtai.core.mapper.shop.EvaluationMapper;
import com.jingtai.shop.service.user.EvaluationService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 * 评价表 服务实现类
 * </p>
 *
 * @author GR123
 * @since 2020-11-29
 */
@Service
public class EvaluationServiceImpl extends ServiceImpl<EvaluationMapper, Evaluation> implements EvaluationService {


    @Resource
    private EvaluationService evaluationService;

    /**
     * 根据商户编码查询评价列表
     * 商品详情
     */
    @Override
    public Page<Evaluation> pageEvaluation(String goodsCode, Long pageNo, Long pageSize) {
        return evaluationService.page(new Page<>(pageNo, pageSize), Wrappers.lambdaQuery(Evaluation.class)
                .eq(Evaluation::getGoodsCode, goodsCode)
                .orderByDesc(Evaluation::getId)
                .eq(Evaluation::getDeleteFlag, DeleteFlagEnum.NOT_DELETE.getCode()));
    }

    /**
     * 用户删除评价
     */
    @Override
    public boolean removeEvaluation(Long id) {
        Evaluation evaluation = new Evaluation();
        evaluation.setId(id);
        evaluation.setDeleteFlag(DeleteFlagEnum.DELETE.getCode());
        return evaluationService.updateById(evaluation);
    }
}
